#include "CreditsState.h"
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "../SGD Wrappers/SGD_InputManager.h"
#include "../SGD Wrappers/SGD_AudioManager.h"
#include "../SGD Wrappers/SGD_String.h"
#include "../Game.h"
#include "MainMenuState.h"

CCreditsState* CCreditsState::GetInstance(void)
{
	static CCreditsState s_Instance;

	return &s_Instance;
}

void CCreditsState::Enter(void)
{
	SGD::GraphicsManager::GetInstance()->SetClearColor({ 0, 0, 0 });
	boom = SGD::GraphicsManager::GetInstance()->LoadTexture("pictures/1407_IForgot_transistionscreen.png");
	SGD::AudioManager::GetInstance()->PlayAudio(Game::GetInstance()->GetBoomSound(), false);
}

void	CCreditsState::Exit(void)
{
	y = 500.0f;
	SGD::GraphicsManager::GetInstance()->UnloadTexture(boom);
	flash = true;
	time = 0.0f;
}

bool CCreditsState::Input(void)
{
	SGD::InputManager* pInput = SGD::InputManager::GetInstance();


	if (pInput->IsKeyPressed(SGD::Key::Escape) == true || pInput->IsButtonPressed(0, 1) == true)
	{
		Game::GetInstance()->ChangeState(CMainMenuState::GetInstance());
		return true;
	}
	return true;
}

void CCreditsState::Render()
{
	const Font* pFont = Game::GetInstance()->GetFont();

	Game* pGame = Game::GetInstance();

	float darkOffset = pGame->DarkOff();
	float medOffset = pGame->MedOff();
	float lightOffset = pGame->LightOff();

	SGD::GraphicsManager::GetInstance()->DrawTexture(pGame->GetDarkSmoke(), { darkOffset, 0 }, 0.0f, { 0, 0 }, { 110, 255, 255, 255 });
	SGD::GraphicsManager::GetInstance()->DrawTexture(pGame->GetMedSmoke(), { medOffset, 0 }, 0.0f, { 0, 0 }, { 127, 255, 255, 255 });
	SGD::GraphicsManager::GetInstance()->DrawTexture(pGame->GetLightSmoke(), { lightOffset, 0 }, 0.0f, { 0, 0 }, { 135, 255, 255, 255 });

	SGD::GraphicsManager::GetInstance()->DrawTexture(pGame->GetDarkSmoke(), { darkOffset - 805, 0 }, 0.0f, { 0, 0 }, { 110, 255, 255, 255 });
	SGD::GraphicsManager::GetInstance()->DrawTexture(pGame->GetMedSmoke(), { medOffset - 805, 0 }, 0.0f, { 0, 0 }, { 127, 255, 255, 255 });
	SGD::GraphicsManager::GetInstance()->DrawTexture(pGame->GetLightSmoke(), { lightOffset - 805, 0 }, 0.0f, { 0, 0 }, { 135, 255, 255, 255 });

	if (flash == false)
	{
		pFont->Draw("Game Core:", { 1, 200.0f + y }, 1, { 0, 255, 0 });
		pFont->Draw("Abdulaziz Bandar\nDominic Dillon", { 1, 300.0f + y }, 1, { 255, 255, 255 });
		pFont->Draw("Animation:", { 1, 600.0f + y }, 1, { 0, 255, 0 });
		pFont->Draw("Luke St. Pierre", { 1, 700.0f + y }, 1, { 255, 255, 255 });
		pFont->Draw("Particles:", { 1, 900.0f + y }, 1, { 0, 255, 0 });
		pFont->Draw("\nAlmando Santos", { 1, 900.0f + y }, 1, { 255, 255, 255 });
		pFont->Draw("Tiles:", { 1, 1200.0f + y }, 1, { 0, 255, 0 });
		pFont->Draw("\nMichael Gergar", { 1, 1200.0f + y }, 1, { 255, 255, 255 });

		pFont->Draw("EP:", { 1, 1500.0f + y }, 1, { 0, 255, 0 });
		pFont->Draw("\nJohn Oleske", { 1, 1500.0f + y }, 1, { 255, 255, 255 });

		pFont->Draw("AP:", { 1, 1800.0f + y }, 1, { 0, 255, 0 });
		pFont->Draw("\nRobert Martinez", { 1, 1800.0f + y }, 1, { 255, 255, 255 });

		pFont->Draw("Artists:", { 1, 2100.0f + y }, 1, { 0, 255, 0 });
		pFont->Draw("\nCaris Frazier", { 1, 2100.0f + y }, 1, { 255, 255, 255 });
		pFont->Draw("\n\nGregory Bey", { 1, 2100.0f + y }, 1, { 255, 255, 255 });
	}
	else
		SGD::GraphicsManager::GetInstance()->DrawTexture(boom, { 0, 0 }, 0.0f, {}, { 255, 255, 255 }, { 1, 1 });

}

void CCreditsState::Update(float elapsedTime)
{
	if (flash == false)
	{
		y -= 0.04f;

		if (y < -2400.0f)
		{
			y = 500.0f;
		}
	}

	if (time > 1.2f)
		flash = false;

	time += elapsedTime;
}